package yb.ecp.fast.feign;


import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import yb.ecp.fast.dto.AccountDTO;
import yb.ecp.fast.dto.AccountPwdDTO;
import yb.ecp.fast.dto.ProfileDTO;
import yb.ecp.fast.dto.RegMemberDTO;
import yb.ecp.fast.dto.SessionDataDTO;
import yb.ecp.fast.dto.TemplateDTO;
import yb.ecp.fast.dto.UserDetailDTO;
import yb.ecp.fast.dto.WorkSpaceDTO;
import yb.ecp.fast.infra.feign.vo.UserLoginVO;
import yb.ecp.fast.infra.infra.ActionResult;

import java.util.List;

/**
 * Created by huaxiulin on 2017/11/20.
 */
@EnableFeignClients
@FeignClient(value = "fast-auth-server", contextId = "authClient2")
public interface AuthClient {

    /**
     * 修改登录名之前需要校验
     *
     * @param accountDTO
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/account/updateLoginName", method = RequestMethod.POST)
    ActionResult updateLoginName(@RequestBody AccountDTO accountDTO) throws Exception;

    /**
     * 增加一个登录名和密码
     *
     * @param accountPwdDTO
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/account/withPwd", method = RequestMethod.PUT)
    ActionResult accountPwd(@RequestBody AccountPwdDTO accountPwdDTO) throws Exception;

    /**
     * 删除一个账号
     *
     * @param loginName
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/account/account", method = RequestMethod.DELETE)
    ActionResult removeAccount(@RequestParam("loginName") String loginName) throws Exception;

    @RequestMapping(
            value = {"/account/removeByUserId"},
            method = {RequestMethod.DELETE}
    )
    ActionResult removeAccountByUserId(@RequestParam("userId") String var1) throws Exception;

    /**
     * 修改密码
     *
     * @param userId
     * @param password
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/account/password", method = RequestMethod.POST)
    ActionResult updatePassword(@RequestParam("userId") String userId, @RequestParam("password") String password) throws Exception;

    /**
     * 删除一个用户所有密码
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/account/password", method = RequestMethod.DELETE)
    ActionResult deletePassword(@RequestParam("userId") String userId) throws Exception;

    @RequestMapping(value = {"/account/resetPassword"}, method = {RequestMethod.POST})
    ActionResult resetPassword(@RequestBody List<String> var1) throws Exception;

    @RequestMapping(value = "/scepter/roleUserIds", method = RequestMethod.GET)
    ActionResult getUserIdsByRoleId(@RequestParam("roleId") String roleId) throws Exception;

    /**
     * 增加角色用户
     *
     * @param roleId
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/scepter/roleUser", method = RequestMethod.POST)
    ActionResult roleUser(@RequestParam("roleId") String roleId, @RequestParam("userId") String userId) throws Exception;


    /**
     * 根据用户ID获取用户对应的角色集合
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/scepter/userRolesList", method = RequestMethod.GET)
    ActionResult userRolesList(@RequestParam("userId") String userId) throws Exception;

    /**
     * 根据用户ID获取用户对应的角色id集合
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/scepter/userRoleIds",method = RequestMethod.GET)
    ActionResult<List<String>> userRoleIds(@RequestHeader("x-user-id")String userId)throws Exception;

    /**
     * 删除角色用户
     *
     * @param roleId String
     * @param userId String
     * @return ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/scepter/removeRoleUser", method = RequestMethod.POST)
    ActionResult removeRoleUser(@RequestParam("roleId") String roleId, @RequestParam("userId") String userId) throws Exception;

    /**
     * 获取用户对应的权限code集合
     *
     * @param roleId String
     * @return ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/scepter/getAuthCodes", method = RequestMethod.GET)
    ActionResult<List<Integer>> getAuthCodes(@RequestParam("roleId") String roleId) throws Exception;

    /**
     * 缓存用户信息
     *
     * @param sessionDataDTO SessionDataDTO
     * @return ActionResult
     */
    @RequestMapping(value = "/usrCtx/session", method = RequestMethod.POST)
    ActionResult session(@RequestBody SessionDataDTO sessionDataDTO) throws Exception;

    /**
     * 增加工作空间
     *
     * @param workSpaceDTO WorkSpaceDTO
     * @return ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/workspace/add", method = RequestMethod.POST)
    ActionResult addWrokSpace(@RequestBody WorkSpaceDTO workSpaceDTO) throws Exception;

    /**
     * 根据ID查询权限模板信息
     *
     * @param id String
     * @return ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/template/itemById", method = RequestMethod.GET)
    ActionResult templateById(@RequestParam("id") String id) throws Exception;

    /**
     * 通过缓存获取用户所属工作空间ID
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/usrCtx/workspaceId", method = RequestMethod.GET)
    ActionResult<String> queryWorkspaceId(@RequestParam("userId") String userId) throws Exception;

    /**
     * 查询工作空间
     *
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/workspace/item", method = RequestMethod.GET)
    ActionResult<WorkSpaceDTO> queryWorkspace(@RequestParam("id") String id);


    /**
     * 获取用户缓存信息
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/profile/userDetail", method = RequestMethod.GET)
    ActionResult<UserDetailDTO> getUserDetail(@RequestParam("userId") String userId) throws Exception;

    /**
     * 获取用户信息(从数据库)
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/profile/detail", method = RequestMethod.GET)
    ActionResult<UserDetailDTO> getUserDbDetail(@RequestParam("userId") String userId);

    /**
     * 增加用户账号基本
     *
     * @param accountPwdDTO AccountPwdDTO
     * @return ActionResult ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/profile/addUserWithAccount", method = RequestMethod.POST)
    ActionResult addUserInfo(@RequestBody AccountPwdDTO accountPwdDTO) throws Exception;

    /**
     * 根据登录名修改用户信息
     *
     * @param profileDTO ProfileDTO
     * @return ActionResult ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/profile/updateUserByAccount", method = RequestMethod.POST)
    ActionResult updateUserByAccount(@RequestBody ProfileDTO profileDTO);

    /**
     * 根据登录名修改用户信息
     *
     * @return ActionResult ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/profile/regMember", method = RequestMethod.POST)
    ActionResult regMember(@RequestBody RegMemberDTO regMemberDTO);


    /**
     * 更换工作空间对应的权限模板
     *
     * @param workspaceId String
     * @param templateId  String
     * @return ActionResult ActionResult
     * @throws Exception Exception
     */
    @RequestMapping(value = "/workspace/updateTemplate", method = RequestMethod.POST)
    ActionResult changeTemplate(@RequestParam("workspaceId") String workspaceId, @RequestParam("templateId") String templateId) throws Exception;

    /**
     * 根据ID删除工作空间（删除企业，需要删除工作空间）
     *
     * @param workspaceId
     * @return
     */
    @RequestMapping(value = "/workspace/remove", method = RequestMethod.DELETE)
    ActionResult removeWorkspace(@RequestParam("workspaceId") String workspaceId);

    /**
     * 锁工作空间
     *
     * @param workspaceId workspaceId
     * @return
     */
    @RequestMapping(value = "/workspace/lock", method = RequestMethod.POST)
    ActionResult lockWorkspace(@RequestParam("workspaceId") String workspaceId);

    /**
     * 解锁工作空间
     *
     * @param workspaceId workspaceId
     * @return
     */
    @RequestMapping(value = "/workspace/unlock", method = RequestMethod.POST)
    ActionResult unlockWorkspace(@RequestParam("workspaceId") String workspaceId);

    @RequestMapping(value = "/template/insert", method = RequestMethod.POST)
    ActionResult addTemplate(@RequestBody TemplateDTO templateDTO);

    @RequestMapping(value = "/template/update", method = RequestMethod.POST)
    ActionResult updateTemplate(@RequestBody TemplateDTO templateDTO);

    @RequestMapping(value = "/template/removeItem", method = RequestMethod.POST)
    ActionResult removeTemplate(@RequestBody TemplateDTO templateDTO);

    @RequestMapping(value = "/template/itemById", method = RequestMethod.GET)
    ActionResult queryTemplateById(@RequestParam("templateId") String templateId);


    /**
     * 校验权限
     *
     * @param userId   String
     * @param authCode long
     * @return ActionResult
     * @throws Exception
     */
    @RequestMapping(value = "/usrCtx/checkAuthCode", method = RequestMethod.GET)
    ActionResult checkAuthCode(@RequestParam("userId") String userId, @RequestParam("authCode") long authCode) throws Exception;

    /**
     * 根据ids 查询用户列表
     * @param userids 用户id数组
     * @return ActionResult ActionResult
     */
    @RequestMapping(value = "/profile/listByIds",method = RequestMethod.POST)
    ActionResult<List<ProfileDTO>> listByIds(@RequestParam("userids") String[] userids);
    @RequestMapping(value = "/auth/authInfo", method = RequestMethod.GET)
    ActionResult GetAuthId();

    /**
     * 查询用户列表,排除操作人,不分页
     * @param profileDTO ProfileDTO
     * @return ActionResult ActionResult
     */
    @RequestMapping(value = "/profile/list4export",method = RequestMethod.POST)
    ActionResult<List<ProfileDTO>> list4export(@RequestBody ProfileDTO profileDTO, @RequestHeader("x-user-id")  String userId );
    @RequestMapping(value = "/auth/login", method = RequestMethod.POST)
    ActionResult<String> Login(@RequestBody UserLoginVO loginVO);

    @RequestMapping(value = "/profile/queryBy400Code", method = RequestMethod.GET)
    ActionResult<String> queryBy400Code(@RequestParam("code400") String code400);

    @RequestMapping({"/profile/getLogin"})
    ActionResult getLogin(@RequestHeader("x-user-id") String var1);
}
